home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 187_01 / getctl.c < prev    next >
C/C++ Source or Header  |  1985-12-28  |  1KB  |  30 lines

  1. /*@*****************************************************/
  2. /*@                                                    */
  3. /*@ getctl - transforms a string containing the        */
  4. /*@        name of a control- character to it's        */
  5. /*@        internal binary value.  E.G. NUL to 0x00.   */
  6. /*@                                                    */
  7. /*@   Usage:     getctl(string);                       */
  8. /*@       where string contains a standard name for a  */
  9. /*@          a control character.                      */
  10. /*@    Returns the binary value or -1 if no match.     */
  11. /*@                                                    */
  12. /*@*****************************************************/
  13.  
  14. #define ERR  -1
  15.  
  16. char getctl(str)
  17. char *str;
  18. {
  19.     static char *cntlchr[] = {"NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL",
  20.         "BS ","HT ","LF ","VT ","FF ","CR ","SO ","SI ","DLE",
  21.         "DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM ",
  22.         "SUB","ESC","FS ","GS ","RS ","US "};
  23.     int i;
  24.  
  25.     for (i=0; i<(sizeof(cntlchr)/sizeof(cntlchr[1])); i++)
  26.         if (strcmp(cntlchr[i],str) == 0)
  27.             return i;
  28.     return ERR;
  29. }
  30.